<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <!--<el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>-->

        <el-select clearable v-model="dataForm.educationId" placeholder="请选择学历" clearable>
          <el-option
            v-for="item in educationOption"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>


        <el-cascader
          clearable
          placeholder="请选择行业信息"
          v-model="industoryArr"
          :options="industryOptions"
          @change="handleChangeIndustoryCondition">
        </el-cascader>


        <el-cascader
          clearable
          placeholder="请选择地址信息"
          v-model="addressArr"
          :options="addressOptions"
          @change="handleChangeAddressCondition">
        </el-cascader>

      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button v-if="isAuth('telnets:talentsrepertory:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
        <el-button v-if="isAuth('telnets:talentsrepertory:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">

      <el-table-column type="expand">
        <template slot-scope="props">
          <div>
            <h4>基本信息：</h4>
          </div>
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="姓名:">
              <span>{{props.row.talentsRepertoryEntity.telnetName}}</span>
            </el-form-item>
            <el-form-item label="年龄:">
              <span>{{props.row.talentsRepertoryEntity.telnetAge}}岁</span>
            </el-form-item>
            <el-form-item label="性别:">
              <el-tag size="small" v-if="props.row.talentsRepertoryEntity.telnetGender == 1">男</el-tag>
              <el-tag size="small" v-else-if="props.row.talentsRepertoryEntity.telnetGender == 0">女</el-tag>
              <el-tag size="small" v-else>性别保密</el-tag>
              <!--<span>{{props.row.talentsRepertoryEntity.telnetGender}}</span>-->
            </el-form-item>
            <el-form-item label="学历:">

              <el-tag  v-if="props.row.talentsRepertoryEntity.educationId == '1'">小学</el-tag>
              <el-tag  v-else-if="props.row.talentsRepertoryEntity.educationId == '2'">初中</el-tag>
              <el-tag  v-else-if="props.row.talentsRepertoryEntity.educationId == '3'">高中</el-tag>
              <el-tag  v-else-if="props.row.talentsRepertoryEntity.educationId == '4'">专科</el-tag>
              <el-tag  v-else-if="props.row.talentsRepertoryEntity.educationId == '5'">本科</el-tag>
              <el-tag  v-else-if="props.row.talentsRepertoryEntity.educationId == '6'">211/985普本</el-tag>
              <el-tag  v-else-if="props.row.talentsRepertoryEntity.educationId == '7'">硕士</el-tag>
              <el-tag  v-else-if="props.row.talentsRepertoryEntity.educationId == '8'">博士</el-tag>
              <el-tag  v-else-if="props.row.talentsRepertoryEntity.educationId == '9'">博士后</el-tag>
              <el-tag  v-else-if="props.row.talentsRepertoryEntity.educationId == '10'">学历不限</el-tag>
              <el-tag  v-else>未知</el-tag>
            </el-form-item>
            <el-form-item label="毕业院校:">
              <span>{{props.row.talentsRepertoryEntity.graduateUniversity}}</span>
            </el-form-item>

            <el-form-item label="联系电话:">
              <span>{{props.row.talentsRepertoryEntity.phone}}</span>
            </el-form-item>
            <el-form-item label="联系微信:">
              <span>{{props.row.talentsRepertoryEntity.wechat}}</span>
            </el-form-item>
            <el-form-item label="专业:">
              <span>{{props.row.talentsRepertoryEntity.major}}</span>
            </el-form-item>
            <el-form-item label="工龄:">
              <span>{{props.row.talentsRepertoryEntity.workAge}}年</span>
            </el-form-item>


            <el-form-item label="期望城市：">
              <span>{{props.row.talentsRepertoryEntity.expAddress}}</span>
            </el-form-item>

            <el-form-item label="期望行业:">
              <span>{{props.row.talentsRepertoryEntity.expIndustory}}</span>
            </el-form-item>
          </el-form>


          <div>
            <h4>教育经历：</h4>
          </div>
          <el-form label-position="left"
                   inline class="demo-table-expand"
                   v-for="itemEducation in props.row.educationList"
                   :key="itemEducation.index"
          >
            <el-form-item label="毕业大学：">
              <span>{{itemEducation.universityName}}</span>
            </el-form-item>

            <el-form-item label="所学专业：">
              <span>{{itemEducation.major}}</span>
            </el-form-item>

            <el-form-item label="毕业时间：">
              <span>{{itemEducation.graduateTime}}</span>
            </el-form-item>

            <el-form-item label="取得学历：">
              <el-tag  v-if="itemEducation.getEducationId == '1'">小学</el-tag>
              <el-tag  v-else-if="itemEducation.getEducationId == '2'">初中</el-tag>
              <el-tag  v-else-if="itemEducation.getEducationId == '3'">高中</el-tag>
              <el-tag  v-else-if="itemEducation.getEducationId == '4'">专科</el-tag>
              <el-tag  v-else-if="itemEducation.getEducationId == '5'">本科</el-tag>
              <el-tag  v-else-if="itemEducation.getEducationId == '6'">211/985普本</el-tag>
              <el-tag  v-else-if="itemEducation.getEducationId == '7'">硕士</el-tag>
              <el-tag  v-else-if="itemEducation.getEducationId == '8'">博士</el-tag>
              <el-tag  v-else-if="itemEducation.getEducationId == '9'">博士后</el-tag>
              <el-tag  v-else-if="itemEducation.getEducationId == '10'">学历不限</el-tag>
              <el-tag  v-else>未知</el-tag>
            </el-form-item>
          </el-form>


          <div>
            <h4>工作履历：</h4>
          </div>
          <el-form label-position="left"
                   inline class="demo-table-expand"
                   v-for="itemworkTrack in props.row.workTrackRecordList"
                   :key="itemworkTrack.index"
          >
            <el-form-item label="企业名称：">
              <span>{{itemworkTrack.companyName}}</span>
            </el-form-item>

            <el-form-item label="担任职责：">
              <span>{{itemworkTrack.holdAPost}}</span>
            </el-form-item>

            <el-form-item label="入职时间：">
              <span>{{itemworkTrack.workBeginTime}}</span>
            </el-form-item>

            <el-form-item label="离职时间：">
              <span>{{itemworkTrack.workEndTime}}</span>
            </el-form-item>
          </el-form>

        </template>

      </el-table-column>


      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>

      <el-table-column
        prop="talentsRepertoryEntity.telnetName"
        header-align="center"
        align="center"
        label="姓名">
      </el-table-column>

      <el-table-column
        prop="talentsRepertoryEntity.telnetAge"
        header-align="center"
        align="center"
        label="年龄">
      </el-table-column>

      <el-table-column
        prop="talentsRepertoryEntity.telnetGender"
        header-align="center"
        align="center"
        label="性别">
        <template slot-scope="scope">
          <el-tag  v-if="scope.row.talentsRepertoryEntity.telnetGender == 1">男</el-tag>
          <el-tag  v-else-if="scope.row.talentsRepertoryEntity.telnetGender == 0">女</el-tag>
          <el-tag  v-else>保密</el-tag>
        </template>
      </el-table-column>

      <el-table-column
        prop="talentsRepertoryEntity.educationId"
        header-align="center"
        align="center"
        label="学历">
        <template slot-scope="scope">
          <el-tag  v-if="scope.row.talentsRepertoryEntity.educationId == '1'">小学</el-tag>
          <el-tag  v-else-if="scope.row.talentsRepertoryEntity.educationId == '2'">初中</el-tag>
          <el-tag  v-else-if="scope.row.talentsRepertoryEntity.educationId == '3'">高中</el-tag>
          <el-tag  v-else-if="scope.row.talentsRepertoryEntity.educationId == '4'">专科</el-tag>
          <el-tag  v-else-if="scope.row.talentsRepertoryEntity.educationId == '5'">本科</el-tag>
          <el-tag  v-else-if="scope.row.talentsRepertoryEntity.educationId == '6'">211/985普本</el-tag>
          <el-tag  v-else-if="scope.row.talentsRepertoryEntity.educationId == '7'">硕士</el-tag>
          <el-tag  v-else-if="scope.row.talentsRepertoryEntity.educationId == '8'">博士</el-tag>
          <el-tag  v-else-if="scope.row.talentsRepertoryEntity.educationId == '9'">博士后</el-tag>
          <el-tag  v-else-if="scope.row.talentsRepertoryEntity.educationId == '10'">学历不限</el-tag>
          <el-tag  v-else>未知</el-tag>
        </template>
      </el-table-column>

      <el-table-column
        prop="talentsRepertoryEntity.graduateUniversity"
        header-align="center"
        align="center"
        label="毕业院校">
      </el-table-column>

      <el-table-column
        prop="talentsRepertoryEntity.phone"
        header-align="center"
        align="center"
        label="联系电话">
      </el-table-column>
      <el-table-column
        prop="talentsRepertoryEntity.wechat"
        header-align="center"
        align="center"
        label="联系微信">
      </el-table-column>
      <el-table-column
        prop="talentsRepertoryEntity.major"
        header-align="center"
        align="center"
        label="所学专业">
      </el-table-column>
      <el-table-column
        prop="talentsRepertoryEntity.workAge"
        header-align="center"
        align="center"
        label="工龄">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.talentsRepertoryEntity.telnetId)">修改</el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row.talentsRepertoryEntity.telnetId)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './talentsrepertory-add-or-update'
  export default {
    data () {
      return {
        dataForm: {
          key: '',
          educationId:undefined,     //按照学历进行筛选
          tradeId: undefined,
          classifyId: undefined,
          jobTypeId: undefined,
          provincesId: undefined,
          citysId: undefined,
          areasId: undefined,
        },

        industoryArr:[],    //按照行业进行筛选
        addressArr:[],      //按照地址进行筛选
        educationOption:[],     //学历背景选择
        addressOptions:[],      //地址选择
        industryOptions:[],     //行业选择

        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
      this.getDataList()
    },
    mounted () {
      this.loadingEducation()
      this.loadingAddress()
      this.loadingIndustory()
    },
    methods: {

      //加载行业
      loadingIndustory(){
        this.$http({
          url: this.$http.adornUrl('/workjobs/workjob/tree-option-ccj'),
          method: 'get'
        }).then(data => {
            this.industryOptions = data.data.data
        })
      },
      //加载地址信息
      loadingAddress(){
        this.$http({
          url: this.$http.adornUrl('/companys/company/tree-option-pcr'),
          method: 'get'
        }).then(data => {
          if (data.data.code === 0){
            this.addressOptions = data.data.data
          }
        })
      },
      //加载学历信息
      loadingEducation(){
        this.$http({
            url: this.$http.adornUrl('/common/education/select-option'),
            method: 'get'
        })
        .then(data => {
          if (data.data.code === 0){
            this.educationOption = data.data.data
          }
        })
      },



      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/telnets/talentsrepertory/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'key': this.dataForm.key,
            'queryCondition':this.dataForm
          })
        }).then(({data}) => {
          console.log("data getList===>",data)
          if (data && data.code === 0) {
            this.dataList = data.data
            this.totalPage = data.total
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.telnetId
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/telnets/talentsrepertory/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },


      handleChangeIndustoryCondition(value){
        console.log("value industory===>",value)
        this.dataForm.tradeId = value[0]
        this.dataForm.classifyId = value[1]
        this.dataForm.jobTypeId = value[2]

      },
      handleChangeAddressCondition(value){
        console.log("value address===>",value)
        this.dataForm.provincesId = value[0]
        this.dataForm.citysId = value[1]
        this.dataForm.areasId = value[2]

      },

    }
  }
</script>


<style>
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }  .demo-table-expand {
       font-size: 0;
     }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }
</style>
